<!-- 本页数据在127行 -->
<template>
    <div>
        <el-card>
            <el-page-header
                content="简历评价列表"
                icon=""
                title="反馈信息"
            />

            <el-table
                :data="state.tableData"
                style="width: 100%"
            >
                <!-- <el-table-column
                    prop="title"
                    label="标题"
                    width="180"
                /> -->
                <el-table-column width="200" label="简历标题">
                    <template #default="scope">
                        {{handleCvTitle(scope.row.cv_id)}}
                    </template>
                </el-table-column>

                <el-table-column width="200" label="信息标题">
                    <template #default="scope">
                        {{handleArticleTitle(scope.row.article_id)}}
                    </template>
                </el-table-column>

                <el-table-column label="建议">
                    <template #default="scope">
                        {{scope.row.advice}}
                    </template>
                </el-table-column>

            </el-table>
        </el-card>

        <el-dialog
            v-model="dialogVisible"
            title="建议详情"
            width="50%"
        >
            <div>
                <h2>{{previewData.title}}</h2>
                <div style="font-size:12px;color:gray;">{{formatTime.getTime(previewData.editTime)}}</div>

                <el-divider>
                    <el-icon>
                        <star-filled />
                    </el-icon>
                </el-divider>

                <div
                    v-html="previewData.content"
                    class="htmlcontent"
                ></div>
            </div>
        </el-dialog>
    </div>
</template>
<script setup>
import { ref, onMounted,reactive } from "vue";
import axios from "axios";
import formatTime from "@/util/formatTime";
import { Star, Edit, Delete, StarFilled, Message } from "@element-plus/icons-vue";
import {useRouter} from 'vue-router'
import {useStore} from 'vuex'
const store = useStore()
const router = useRouter()
let state = reactive({
    tableData:[],
    CvsOfUser:[],
    resultOfArticle:[],
    resultOfPostRecord:[]
})
const previewData = ref({});
const dialogVisible = ref(false);
onMounted(() => {
  getTableData();
});

const getTableData = async () => {
   
    //通过userid查找该教师对应的所有资料

    state.tableData = [
        
    ]
    let Cvs = await axios.get(`/cv/findByAuthor?author=${store.state.userInfo.id}`)
    console.log(Cvs)
    state.CvsOfUser = Cvs.data.data
    let cvids = []
    for(let i=0;i<Cvs.data.data.length;i++){
        cvids[i] = Cvs.data.data[i].id
    }
    let res = await axios.post("/postRecord/findByCv_ids",cvids)
    let articleIds = []
    for(let i=0;i<res.data.data.length;i++){
        articleIds[i] = res.data.data[i].article_id
    }

    let result = await axios.post("/article/findByIds",articleIds)
    let resultOfArticle = result.data.data
    let resultOfPostRecord = res.data.data
    // console.log(resultOfArticle)
    // console.log(resultOfPostRecord)

    state.resultOfArticle = resultOfArticle
    state.resultOfPostRecord = resultOfPostRecord

    state.tableData = resultOfPostRecord
    
};

const handleCvTitle=(cv_id)=>{
    for(let i=0;i<state.CvsOfUser.length;i++){
        if(cv_id===state.CvsOfUser[i].id){
            return state.CvsOfUser[i].title
        }
    }
}

const handleArticleTitle=(article_id)=>{
    for(let i=0;i<state.resultOfArticle.length;i++){
        if(article_id===state.resultOfArticle[i].id){
            return state.resultOfArticle[i].title
        }
    }
}

//预览回调
const handlePreview = data => {
  // console.log(data)
  previewData.value = data;
  dialogVisible.value = true;
};

//删除回调
const handleDelete =async (item)=>{
    // console.log(item)
    // await axios.delete(`/adminapi/news/list/${item._id}`)
    // await getTableData()
    console.log(item.id)
    await axios.delete(`/article/deleteById?id=${item.id}`)

    let table = await axios.get(`/article/findByAuthor?author=${store.state.userInfo.id}`)
    state.tableData = table.data.data
}

//编辑回调
const handleEdit = (item)=>{
    //跳转到/news-manage/editnews/:id

    router.push(`/information-manage/edit/${item.id}`)
}

//查看投递到简历
const handlePosts = (item)=>{

    router.push(`/information-manage/checkCvs/${item.id}`)

}
</script>
<style lang="scss" scoped>
.el-table {
  margin-top: 50px;
}

::v-deep .htmlcontent {
  img {
    max-width: 100%;
  }
}
</style>
